/*
 * @Author: Hp_lucky 1063512385@qq.com
 * @Date: 2024-09-28 14:34:52
 * @LastEditors: Hp_lucky 1063512385@qq.com
 * @LastEditTime: 2024-10-14 17:45:01
 * @FilePath: \lucky-rpg\assets\script\src\Basic\Model\Effect\EffectAnimation.ts
 */
import { _decorator, ParticleSystem2D, Sprite, SpriteFrame } from 'cc';
import { Effect } from './Effect';
import { LoadingManager } from '../../Manager/LoadingManager';
const { ccclass, property } = _decorator;

@ccclass('EffectSprite')
export class EffectSprite extends Effect {
  @property(Sprite)
  private sprite: Sprite = null!;
  @property(ParticleSystem2D)
  private particle: ParticleSystem2D = null!;
  protected onEnable() {
    if (this.particle && this.particle.resetSystem) this.particle.resetSystem();
    LoadingManager.Ins()
      .loadDynamicsRes<SpriteFrame>(this.effParam + '/spriteFrame')
      .then((spr) => {
        this.sprite.spriteFrame = spr;
      });
  }

  unuse() {
    this.sprite.spriteFrame = null;
    LoadingManager.Ins().releaseDynamicRes(this.effParam + '/spriteFrame');
    super.unuse();
  }
}
